<html>
<head>
  <meta HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=ISO-8859-1">
  <title>pboundary.m</title>
<link rel="stylesheet" type="text/css" href="../../m-syntax.css">
</head>
<body>
<code>
<span class=defun_kw>function</span>&nbsp;<span class=defun_out>varargout</span>=<span class=defun_name>pboundary</span>(<span class=defun_in>model,options</span>)<br>
<span class=h1>%&nbsp;PBOUNDARY&nbsp;Plots&nbsp;decision&nbsp;boundary&nbsp;of&nbsp;given&nbsp;classifier&nbsp;in&nbsp;2D.</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Synopsis:</span></span><br>
<span class=help>%&nbsp;&nbsp;h&nbsp;=&nbsp;pboundary(model)</span><br>
<span class=help>%&nbsp;&nbsp;h&nbsp;=&nbsp;pboundary(model,options)</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Description:</span></span><br>
<span class=help>%&nbsp;&nbsp;This&nbsp;function&nbsp;plots&nbsp;decision&nbsp;boundary&nbsp;of&nbsp;given&nbsp;classifier&nbsp;in&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;2-dimensional&nbsp;feature&nbsp;space.&nbsp;The&nbsp;classification&nbsp;function</span><br>
<span class=help>%&nbsp;&nbsp;must&nbsp;be&nbsp;specified&nbsp;in&nbsp;the&nbsp;field&nbsp;model.eval.&nbsp;The&nbsp;decision</span><br>
<span class=help>%&nbsp;&nbsp;bounary&nbsp;is&nbsp;interpolated&nbsp;from&nbsp;the&nbsp;response&nbsp;of&nbsp;the&nbsp;classifier</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;y&nbsp;=&nbsp;feval(&nbsp;model.fun,&nbsp;X,&nbsp;model).</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Input:</span></span><br>
<span class=help>%&nbsp;&nbsp;model&nbsp;[struct]&nbsp;Model&nbsp;of&nbsp;classifier.</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;.fun&nbsp;[string]&nbsp;Classification&nbsp;function.</span><br>
<span class=help>%&nbsp;&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;options&nbsp;[struct]&nbsp;Controls&nbsp;visualization:</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;.gridx&nbsp;[1x1]&nbsp;Sampling&nbsp;density&nbsp;in&nbsp;x-axis&nbsp;(default&nbsp;200).</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;.gridy&nbsp;[1x1]&nbsp;Sampling&nbsp;density&nbsp;in&nbsp;y-axis&nbsp;(default&nbsp;200).</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;.line_style&nbsp;[string]&nbsp;Used&nbsp;line-style&nbsp;to&nbsp;plot&nbsp;decision&nbsp;boundary.</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;.fill&nbsp;[1x1]&nbsp;If&nbsp;1&nbsp;then&nbsp;the&nbsp;class&nbsp;regions&nbsp;are&nbsp;filled.&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;</span><br>
<span class=help>%&nbsp;<span class=help_field>Output:</span></span><br>
<span class=help>%&nbsp;&nbsp;h&nbsp;[1&nbsp;x&nbsp;nobjects]&nbsp;Handles&nbsp;of&nbsp;used&nbsp;graphics&nbsp;objects.</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Example:</span></span><br>
<span class=help>%&nbsp;&nbsp;data&nbsp;=&nbsp;load('riply_trn');</span><br>
<span class=help>%&nbsp;&nbsp;figure;&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;ppatterns(data);</span><br>
<span class=help>%&nbsp;&nbsp;pboundary(&nbsp;knnrule(data,1)&nbsp;);</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;See&nbsp;also&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;PPATTERNS,&nbsp;PLINE.</span><br>
<span class=help>%</span><br>
<hr>
<span class=help1>%&nbsp;<span class=help1_field>About:</span>&nbsp;Statistical&nbsp;Pattern&nbsp;Recognition&nbsp;Toolbox</span><br>
<span class=help1>%&nbsp;(C)&nbsp;1999-2003,&nbsp;Written&nbsp;by&nbsp;Vojtech&nbsp;Franc&nbsp;and&nbsp;Vaclav&nbsp;Hlavac</span><br>
<span class=help1>%&nbsp;&lt;a&nbsp;href="http://www.cvut.cz"&gt;Czech&nbsp;Technical&nbsp;University&nbsp;Prague&lt;/a&gt;</span><br>
<span class=help1>%&nbsp;&lt;a&nbsp;href="http://www.feld.cvut.cz"&gt;Faculty&nbsp;of&nbsp;Electrical&nbsp;Engineering&lt;/a&gt;</span><br>
<span class=help1>%&nbsp;&lt;a&nbsp;href="http://cmp.felk.cvut.cz"&gt;Center&nbsp;for&nbsp;Machine&nbsp;Perception&lt;/a&gt;</span><br>
<br>
<span class=help1>%&nbsp;<span class=help1_field>Modifications:</span></span><br>
<span class=help1>%&nbsp;1-may-2004,&nbsp;VF</span><br>
<span class=help1>%&nbsp;19-may-2003,&nbsp;VF</span><br>
<br>
<hr>
<span class=comment>%&nbsp;process&nbsp;inputs</span><br>
<span class=keyword>if</span>&nbsp;<span class=stack>nargin</span>&nbsp;&lt;&nbsp;1,&nbsp;<span class=error>error</span>(<span class=quotes>'Not&nbsp;enough&nbsp;input&nbsp;arguments.'</span>);&nbsp;<span class=keyword>end</span><br>
model=c2s(model);<br>
<br>
<span class=keyword>if</span>&nbsp;<span class=stack>nargin</span>&nbsp;&lt;&nbsp;2,&nbsp;options=[];&nbsp;<span class=keyword>else</span>&nbsp;options=c2s(options);&nbsp;<span class=keyword>end</span><br>
<span class=keyword>if</span>&nbsp;~isfield(options,<span class=quotes>'fill'</span>),&nbsp;options.fill=0;&nbsp;<span class=keyword>end</span><br>
<span class=keyword>if</span>&nbsp;~isfield(options,<span class=quotes>'gridx'</span>),&nbsp;options.gridx&nbsp;=&nbsp;200;&nbsp;<span class=keyword>end</span><br>
<span class=keyword>if</span>&nbsp;~isfield(options,<span class=quotes>'gridy'</span>),&nbsp;options.gridy&nbsp;=&nbsp;200;&nbsp;<span class=keyword>end</span><br>
<span class=keyword>if</span>&nbsp;~isfield(options,<span class=quotes>'line_style'</span>),&nbsp;options.line_style&nbsp;=&nbsp;<span class=quotes>'k'</span>;&nbsp;<span class=keyword>end</span><br>
<br>
<span class=comment>%&nbsp;get&nbsp;hold&nbsp;option</span><br>
old_hold&nbsp;=&nbsp;ishold;<br>
hold&nbsp;on;<br>
<br>
<span class=comment>%</span><br>
V&nbsp;=&nbsp;<span class=graph>axis</span>;<br>
dx&nbsp;=&nbsp;(V(2)-V(1))/options.gridx;<br>
dy&nbsp;=&nbsp;(V(4)-V(3))/options.gridy;<br>
<br>
[X,Y]&nbsp;=&nbsp;meshgrid(V(1):dx:V(2),V(3):dy:V(4));<br>
<br>
<span class=comment>%&nbsp;make&nbsp;testing&nbsp;points</span><br>
tst_data=[reshape(X<span class=quotes>',1,prod(size(X)));reshape(Y'</span>,1,prod(size(Y)))];<br>
<br>
<span class=comment>%&nbsp;classify&nbsp;points</span><br>
D&nbsp;=&nbsp;<span class=eval>feval</span>(&nbsp;model.fun,&nbsp;tst_data,&nbsp;model&nbsp;);<br>
<br>
h&nbsp;=&nbsp;plot_boundary(&nbsp;D,&nbsp;V(1):dx:V(2),&nbsp;V(3):dy:V(4),&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;options.fill,&nbsp;options.line_style&nbsp;);<br>
<br>
<span class=keyword>if</span>&nbsp;~old_hold,&nbsp;hold&nbsp;off;&nbsp;<span class=keyword>end</span><br>
<br>
<span class=comment>%&nbsp;return&nbsp;handles&nbsp;if&nbsp;required</span><br>
<span class=keyword>if</span>&nbsp;<span class=stack>nargout</span>&nbsp;&gt;&nbsp;0,&nbsp;<span class=stack>varargout</span>{1}&nbsp;=&nbsp;h;&nbsp;<span class=keyword>end</span><br>
<br>
<span class=jump>return</span>;<br>
<br>
<span class=comment>%-------------------------------------------------------</span><br>
<span class=defun_kw>function</span>&nbsp;<span class=defun_out>h&nbsp;</span>=&nbsp;<span class=defun_name>plot_boundary</span>(<span class=defun_in>&nbsp;L,&nbsp;X_pos,&nbsp;Y_pos,&nbsp;fill_regions,&nbsp;linestyle&nbsp;</span>)<br>
<span class=comment>%&nbsp;Plots&nbsp;decision&nbsp;boudary.&nbsp;</span><br>
<span class=comment>%</span><br>
<br>
dx=X_pos(2)-X_pos(1);<br>
dy=Y_pos(2)-Y_pos(1);<br>
m&nbsp;=&nbsp;length(&nbsp;X_pos&nbsp;);<br>
n&nbsp;=&nbsp;length(&nbsp;Y_pos&nbsp;);<br>
<br>
Z&nbsp;=&nbsp;NaN*ones(&nbsp;m+2,&nbsp;n+2&nbsp;);<br>
num_classes&nbsp;=&nbsp;max(L(:));<br>
<br>
<span class=comment>%&nbsp;mask=fspecial('gauss',[5&nbsp;5],1)&nbsp;;&nbsp;%&nbsp;fspecial&nbsp;is&nbsp;from&nbsp;images&nbsp;toolbox&nbsp;</span><br>
mask&nbsp;=&nbsp;[0.0030&nbsp;&nbsp;&nbsp;&nbsp;0.0133&nbsp;&nbsp;&nbsp;&nbsp;0.0219&nbsp;&nbsp;&nbsp;&nbsp;0.0133&nbsp;&nbsp;&nbsp;&nbsp;0.0030;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0.0133&nbsp;&nbsp;&nbsp;&nbsp;0.0596&nbsp;&nbsp;&nbsp;&nbsp;0.0983&nbsp;&nbsp;&nbsp;&nbsp;0.0596&nbsp;&nbsp;&nbsp;&nbsp;0.0133;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0.0219&nbsp;&nbsp;&nbsp;&nbsp;0.0983&nbsp;&nbsp;&nbsp;&nbsp;0.1621&nbsp;&nbsp;&nbsp;&nbsp;0.0983&nbsp;&nbsp;&nbsp;&nbsp;0.0219;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0.0133&nbsp;&nbsp;&nbsp;&nbsp;0.0596&nbsp;&nbsp;&nbsp;&nbsp;0.0983&nbsp;&nbsp;&nbsp;&nbsp;0.0596&nbsp;&nbsp;&nbsp;&nbsp;0.0133;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0.0030&nbsp;&nbsp;&nbsp;&nbsp;0.0133&nbsp;&nbsp;&nbsp;&nbsp;0.0219&nbsp;&nbsp;&nbsp;&nbsp;0.0133&nbsp;&nbsp;&nbsp;&nbsp;0.0030];<br>
<br>
h&nbsp;=&nbsp;[];&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
<span class=keyword>for</span>&nbsp;i&nbsp;=&nbsp;1:num_classes,<br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;A=L;<br>
&nbsp;&nbsp;A(find(L==i))=1;<br>
&nbsp;&nbsp;A(find(L~=i))=-1;<br>
&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;A&nbsp;=&nbsp;reshape(&nbsp;A',&nbsp;m,&nbsp;n&nbsp;);<br>
&nbsp;&nbsp;A&nbsp;=&nbsp;filter2(mask,&nbsp;A);<br>
&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;Z(2:<span class=keyword>end</span>-1,2:<span class=keyword>end</span>-1)&nbsp;=&nbsp;A;&nbsp;&nbsp;<br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;[cc,tmp_h]&nbsp;=&nbsp;contour([X_pos(1)-dx,X_pos,X_pos(<span class=keyword>end</span>)+dx],...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[Y_pos(1)-dy,Y_pos,Y_pos(<span class=keyword>end</span>)+dy],Z',[-0&nbsp;0],linestyle);&nbsp;&nbsp;<br>
&nbsp;&nbsp;h&nbsp;=&nbsp;[h&nbsp;tmp_h(:)'];<br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;<span class=keyword>if</span>&nbsp;fill_regions,<br>
&nbsp;&nbsp;&nbsp;<span class=keyword>while</span>&nbsp;~isempty(cc)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;len&nbsp;=&nbsp;cc(2,1);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp_h&nbsp;=&nbsp;fill(cc(1,2:len+1),cc(2,2:len+1),marker_color(i));<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h&nbsp;=&nbsp;[h&nbsp;tmp_h(:)'];<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cc(:,1:len+1)&nbsp;=&nbsp;[];<br>
&nbsp;&nbsp;&nbsp;<span class=keyword>end</span>&nbsp;&nbsp;<br>
&nbsp;&nbsp;<span class=keyword>end</span><br>
<span class=keyword>end</span><br>
<br>
<span class=jump>return</span>;<br>
<br>
</code>
